package cn.ai.shoes.client.controller;

import cn.ai.shoes.client.entity.ComfyuiTask;
import cn.ai.shoes.client.entity.modelvo.*;
import cn.ai.shoes.client.entity.vo.ComfyuiReturnVo;
import cn.ai.shoes.client.service.ImageService;
import cn.ai.shoes.client.annotation.ComfyuiLogAnnotation;


import cn.ai.shoes.common.constant.GolbalConstants;
import cn.ai.shoes.common.pojo.entity.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;

/**
 * 图生图控制器
 * @author
 * @since 2024-03-24
 * @version 1.0z
 */
@RestController
@RequestMapping("/image")
@Tag(name = "图生图",description = "图生图")
public class ImageController {
    public static final String KT_IMAGE = "ktImage";
    public static final String TJTWS_IMAGE = "tjtwsImage";
    public static final String STRHZXS_IMAGE = "strhzxsImage";
    public static final String TJTOK_IMAGE = "tjtokImage";
    public static final String LOREWST_IMAGE = "lorewstImage";
    public static final String GQFD_IMAGE = "gqfdImage";
    public static final String XDHH_IMAGE = "xdhhImage";
    public static final String JBCH_IMAGE = "jbchImage";
    public static final String XC_IMAGE = "xcImage";
    public static final String XF_IMAGE = "xfImage";
    @Resource
    private ImageService imageService;
    /**
     * 请求任务
     */
    @GetMapping("/request")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "请求等待结果",description = "请求等待结果")
    public CommonResult request(String pi,String server) throws Exception {
        return CommonResult.success(imageService.requestByPromptId(pi,server));
    }
    /**
     * 抠图
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/kt")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "抠图",description = "抠图")
    public CommonResult ktImage(@RequestBody @Validated KtModelVo vo) throws Exception {
        ComfyuiTask task = imageService.ktImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 图加图无锁
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/tjtws")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "图加图无锁",description = "图加图无锁")
    public CommonResult tjtwsImage(@RequestBody @Validated TjtwsModelVo vo) throws Exception {
        ComfyuiTask task = imageService.tjtwsImage(vo);
        return CommonResult.success(task);
    }

    /**
     * 图像融合最新锁
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/strhzxs")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "图像融合最新锁",description = "图像融合最新锁")
    public CommonResult strhzxsImage(@RequestBody @Validated StrhzxsModelVo vo) throws Exception {
        // ComfyuiReturnVo result = imageService.strhzxsImage(vo);
        ComfyuiTask task = imageService.strhzxsImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 图加图OK
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/tstok")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "图加图OK",description = "图加图OK")
    public CommonResult tstokImage(@RequestBody @Validated TstokModelVo vo) throws Exception {
        ComfyuiTask task = imageService.tjtokImage(vo);
        return CommonResult.success(task);
    }

    /**
     * lore文生图
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/lorewst")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "Lore文生图",description = "Lore文生图")
    public CommonResult lorewstImage(@RequestBody @Validated LorewstModelVo vo) throws Exception {
        ComfyuiTask task = imageService.lorewstImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 高清放大
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/gqfd")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "高清放大",description = "高清放大")
    public CommonResult gqfdImage(@RequestBody @Validated GqfdModelVo vo) throws Exception {
        ComfyuiTask task = imageService.gqfdImage(vo);
        return CommonResult.success(task);
    }

    /**
     * 鞋底互换（蒙版）
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/xdhh")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "鞋底互换（蒙版）",description = "鞋底互换（蒙版）")
    public CommonResult xieDiImage(@RequestBody @Validated XdhhModelVo vo) throws Exception {
        ComfyuiTask task = imageService.xdhhImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 局部重绘（蒙版）
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/jbch")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "局部重绘（蒙版）",description = "局部重绘（蒙版）")
    public CommonResult jbchImage(@RequestBody @Validated JbchModelVo vo) throws Exception {
        ComfyuiTask task = imageService.jbchImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 消除（蒙版）
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/xc")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "消除（蒙版）",description = "消除（蒙版）")
    public CommonResult xcImage(@RequestBody @Validated XcModelVo vo) throws Exception {
        ComfyuiTask task = imageService.xcImage(vo);
        return CommonResult.success(task);
    }
    /**
     * 消除（蒙版）
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping("/gene/xf")
    @ComfyuiLogAnnotation
    @PreAuthorize(GolbalConstants.RoleConstants.ROLE_MEMBER_ADMIN)
    @Operation(summary = "修复（蒙版）",description = "修复（蒙版）")
    public CommonResult xfImage(@RequestBody @Validated XfModelVo vo) throws Exception {
        ComfyuiTask task = imageService.xfImage(vo);
        return CommonResult.success(task);
    }
}
